//
//  APIConfig.swift
//  ezyform
//
//  Created by FengMoennig on 11/19/15.
//  Copyright © 2015 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SwiftyJSON
//define return block after network access
public typealias ReturnValueBlock = (_ result : Any?, _ otherInfo: NSDictionary? )->Void
public typealias ErrorCodeBlock = (_ code: String,_ error : String)->Void
class APIConfig: NSObject {
    //基本定位Key
    static let GoogleMapKey: String = "AIzaSyAbhLG4jcxt7C86vEP10IqIl_AAfKYunoQ"
    //request longitude and latitude according to address with google api
    static let GeocodingGoogleAPI: String = "https://maps.googleapis.com/maps/api/geocode/json?address="
    //force version
    static let AppForceUpdateAPI: String = "last_version"
    //force version
    static let ScanOfflieLicenseAPI: String = "scan_barcode_license"
    //get the latest APP Version info on apple store
    static let AppVersionAPI: String = "https://itunes.apple.com/au/lookup?id=1190767725"//"https://apps.apple.com/us/app/greendeal/id1190767725"//
    //forward to app store to upgrade 
    static let AppUpgradeAPI: String = "https://apps.apple.com/us/app/id1190767725?ls=1"
    //spv 规则介绍链接
    static let SPVLink: String = "https://www.cleanenergyregulator.gov.au/RET/Scheme-participants-and-industry/Solar-Panel-Validation-initiative"
    //Update Password
    static let UpdatePasswordAPI : String = "settings/password"
    
    //Service Job List
    static let ServiceJobListAPI : String = "service_jobs"
    
    //Installations Detail
    class var InstallationDetailAPI : String {
        return "pvds/detail?id="
    }
    //Installations Detail
    class var ServiceJobDetailAPI : String {
        return "service_jobs/detail?id="
    }
    //get pvd check list
    class var GetPVDCheckListAPI : String {
        return "pvds/checklist?id="
    }
    //check all field when Register submit
    class var CheckFieldWhenRegisterAPI : String {
        return "installers/check_field"
    }
    //check accredited number and name 是否在CEC存在 when Register submit
    class var CheckAccreditedNumberAndNameWhenRegisterAPI : String {
        return "installers/check_accredited_number_and_name"
    }
    //check accredited number and email when Register submit
    class var SubmitRegisterInfoAPI : String {
        return "installers/register"
    }
    //get panel number list
    class var GetPanelNumbersAPI : String {
        return "pvds/serial_numbers?pvd_id="
    }
    //get inverter number
    class var GetInverterNumberListAPI: String {
        return "pvds/inverter_serial_numbers"
    }
    //get service check list
    class var GetServiceJobCheckListAPI : String {
        return "service_jobs/checklist?id="
    }
    class var UploadServiceJobCheckListAPI : String {
        return "service_jobs/checklist"
    }
    //upload check list
    class var UploadCheckListInfoAPI : String {
        return "pvds/upload_checklist"
    }
    
    class var UploadServiceJobDetailInfoAPI : String {
        return "service_jobs/upload"
    }

    class var UploadServiceJobCheckListInfoAPI : String {
        return "service_jobs/upload_checklist"
    }
    //upload signatures and panel number old API
    class var UploadInstallationInfoAPI : String {
        return "pvds/upload"
    }
    
    //upload signatures
    class var UploadSignaturesAPI : String {
        return "pvds/upload_signatures"
    }
    //upload panel number
    class var UploadPanelNumbersAPI : String {
        return "pvds/upload_serial_numbers"
    }
    //upload inverter number
    class var UploadInverterNumbersAPI : String {
        return "pvds/upload_inverter_serial_numbers"
    }
    //upload tank number
    class var UploadTankNumbersAPI : String {
        return "pvds/upload_tank_serial_numbers"
    }
    //finish job
    class var StartJobAPI : String {
        return "pvds/start_job"
    }
    class var StartServiceJobAPI : String {
        return "service_jobs/start_job?id="
    }
    //finish job
    class var FinishJobAPI : String {
        return "pvds/finish_job"
    }
    class var FinishServiceJobAPI : String {
        return "service_jobs/finish_job?id="
    }
    //reopen job
    class var ReopenJobAPI : String {
        return "pvds/reopen_job?id="
    }
    class var ReopenServiceJobAPI : String {
        return "service_jobs/reopen_job?id="
    }
    //my information
    class var MyInformationAPI : String {
        return "installers/detail"
    }
    //change password
    class var ResetPasswordAPI : String {
        return "installers/reset_password"
    }
    //update ui style
    class var UpdateUIStyleAPI : String {
        return "installers/set_ui_style"
    }
    //update checklist ui style
    class var UpdateChecklistUIStyleAPI : String {
        return "installers/set_checklist_ui_style"
    }
    //set firebase token
    class var SetFirebaseTokenAPI : String {
        return "installers/set_fire_base_token"
    }
    //Push notification API
    class var PushNotificationRegister : String {
        return "notifications/register"
    }
    class var PushNotificationUpdateRead : String {
        return "notifications/read"
    }
    class var PushNotificationGetUnRead : String {
        return "notifications/unread"
    }
    //V2 API Below
    //Login
    static let LoginAPI : String = "sessions"
    static let SendEmailConfirmAPI: String = "resend_mail"
    //Installations List
    static let InstallationsListAPI : String = "pvds"
    
    //panel installed
    static let PanelInstallValidateAPI : String = "solar_panel_validation/installation_verification"
    
    //Bid jobs list or My jobs list
    static let BidJobsListAPI : String = "service_jobs"
    
    //Bid job detail or My job detail
    static let BidJobDetailAPI : String = "service_jobs/detail?id="
    
    //Make an offer
    static let MakeAnOfferAPI : String = "service_jobs/make_an_offer"
    
    //Get question list
    static let QuestionListAPI : String = "service_jobs/question_list?id="
    
    //Get History List
    static let HistoryListAPI : String = "service_jobs/histories?id="
    
    //ask question
    static let AskQuestionAPI : String = "service_jobs/ask_question"
    
    //reply question
    static let ReplyQuestionAPI : String = "service_jobs/reply_question"
    
    //Accept job
    static let AcceptBidJobAPI : String = "service_jobs/accept_job"
    
    //Start Job
    static let StartBidJobAPI : String = "service_jobs/start_job"
    
    //Finish job
    static let FinishBidJobAPI : String = "service_jobs/finish_job"
    
    static let GetAllPVDJobsForCurrentUser = "pvds/get_all_job_status"
    
    static let GetAllServiceJobsForCurrentUser = "service_jobs/get_all_job_status"
    
    static let ForgotPwdAPI: String = "forgot_password"
    static let SentVerificationCode: String = "installers/send_verification_code_mail"
    
    static let DeleteAccount: String = "installers/destroy"
    //会员积分
    static let CurrentTotalPointsAPI: String = "points/point"//当前积分总数
    static let PointsListAPI: String = "points/point_list"//积分历史记录，有加分有减分
    static let PointDescriptionAPI: String = "points/point_description"//当前积分总数
    //基础数据
    static let StateListAPI: String = "dictionaries/state_list" //State list
    static let SuburbListAPI: String = "dictionaries/suburb_list" //Suburb list
    static let StreetTypeListAPI: String = "dictionaries/street_type_list" //Street type list
    static let UnitTypeListAPI: String = "dictionaries/unit_type_list" //unit type
    //修改Installation Detail中的安装地址
    static let ChangeInstallationAddressAPI: String = "pvds/change_installation_address"
    //记录错误日志error log, only for panel instatlled and panel number
    static let ErrorLogAPI: String = "pvds/error_log"
    //给owner发送签名信息
    static let SendSMSToOwner = "pvds/send_owner_signature_phone"
    //给owner发送签名邮件
    static let SendEmailToOwner = "pvds/send_owner_signature_mail"
    //根据pvd ids查看job有没有没有读的error 历史记录
    static let ErrorNotReadAPI = "pvds/error_history_not_read"
    //查看某一个job的所有error 历史记录，按照id降序排列
    static let ErrorHistoriesAPI = "pvds/error_histories"
    static let UploadAttachmentAPI = "pvds/upload_document"
    static let DeleteAttachmentAPI = "pvds/delete_document"
    //App comment
    static let AppCommentAPI = "installer_ratings/"
    //resign statemennt
    static let ReadResignStatementMsgAPI = "pvds/read_re_sign_statement_message"//提交此API表示用户已读重新签名的弹出信息了
    // MARK: - notifications
    // Notifications List
    static let NotificationsListAPI = "notifications"
    // Notifications Detail，只要调用detail API，后台就标记此消息已读
    static let NotificationsDetailAPI = "notifications/detail"
    // Notifications Read，All read时，设置所有消息为已读
    static let NotificationsReadAPI = "notifications/read"
    // Notifications Unread Count
    static let NotificationsUnreadCountAPI = "notifications/unread_count"
    //更新owner info
    static let UpdateOwnerInfoAPI = "pvds/update_owner_name"
    //check ABN
    static let GetCompanyNameByABNAPI = "dictionaries/get_company_name"
    //根据query str查询panel list
    static let GetPanelModelListAPI = "dictionaries/panel_brand_list?q="//
    //根据query str查询inveter list
    static let GetInverterModelListAPI = "dictionaries/inverter_brand_list?q="
    //根据query str查询battery list
    static let GetBatteryModelListAPI = "dictionaries/battery_storage_list?q="
    //根据query str查询tank list
    static let GetTankModelListAPI = "dictionaries/water_heater_list?q="
    //更新Job中的panel ， inverter 信息
    static let UpdateSystemInfoAPI = "pvds/update_panel_and_inverter"
    //更新Job中的installation type,  附加信息
    static let UpdateInstallationTypeAPI = "pvds/update_installation_type"
    //更新Job中的grid connected
    static let UpdateConnectedTypeAPI = "pvds/update_connected_type"
    //pop over title
    static let GetPopOverTitleAPI = "dictionaries/popover_title?"
    //上传installer avatar头像
    static let UploadAvatarImage = "installers/set_avatar"
    //获取installer的
    static let GetJobsCntAndReward = "pvds/stc_job_count_and_installer_reward"
    //根据地址字符串，获取地址列表
    static let GetAddressListAPI = "dictionaries/address_search"
    //******创建Job相关的API
    //1.获取installer所在的company
    static let GetCompanyListAPI = "installers/get_company_list"
    //2.获取某个company所在的agent
    static let GetAgentListAPI = "dictionaries/get_agent_list?company_id="
    //2.1 获取当前installer某个时间段内的Jobs的状态
    static let GetJobsStatusBetweenDate = "pvds/install_job_status"
    //3.获取某个installer列表
    static let GetInstallerListAPI = "installers/get_installer_list"
    //4.获取某个designer列表
    static let GetDesignerListAPI = "installers/get_designer_list"
    //5.获取某个electrician列表
    static let GetElectricialListAPI = "installers/get_electrician_list"
    //5.根据panel的总watts数，获取stcs的数量
    static let GetStcsByTotalPanelWatts = "pvds/job_quantity"
    //6.创建Job
    static let CreateJobAPI = "pvds/create_job"
    //7.创建Job前先调用是否开启spv的验证
    static let ValidSPVCheckBeforeUpdatePanelAPI = "pvds/valid_spv_check"
    //******
    //获取天气接口
    static let GetWeatherAPI = "dictionaries/get_weather"
    //获取仓库列表接口
    static let GetDeliveryListAPI = "dictionaries/get_delivery_list"
    //创建仓库地址接口
    static let CreateDeliveryAPI = "dictionaries/create_delivery"
    //SettingTermsAndCondition待处理
    static let SettingTermsAndCondition = "app_termsconditions"
    static let LoginprivacyPolicy = "policy/privacy"
    static let LoginTermsConditions = "app_termsconditions"
    static let RegisterprivacyPolicy = "policy/privacy"
    static func getRequestAPI(_ keyWord : String,pvdId :String = "") -> String {
        var fullAPIString = APPConfig.serverAddress + "api/v1/" + keyWord
        if pvdId != "" {
            fullAPIString += pvdId
        }
        return fullAPIString
    }
    static func getRequestAPIForV2(_ keyWord : String,id :String = "") -> String {
        var fullAPIString = APPConfig.serverAddress + "api/v2/installer_app/" + keyWord
        if id != "" {
            fullAPIString += id
        }
        
        return fullAPIString
    }
    //PVD ID加密，获取retailer，installer，designer已签名文档
    static func getWebSignStatement(_ keyWord : String,pvdId :String = "") -> String {
        let encodeJobID = Encryption.Endcode_AES_ECB(strToEncode: pvdId)
        let fullAPIString = APPConfig.serverAddress + "web_sign/" + encodeJobID + "/" + keyWord + "?is_mobile_view=true"
        return fullAPIString
    }
}
